//
// Created by 束庆乐 on 2025/1/1.
//
#include "iostream"
using namespace std;

class Person{
public:
    int* mage;
    Person(int age){
        //将年龄数据开辟到堆区
        mage = new int(age);
    }
    //重载赋值运算符
    Person& operator=(Person& p){
        if(mage != NULL){
            delete mage;
            mage = NULL;
        }
        //编译器提供浅拷贝
//        mage = p.mage;
        //深拷贝
        mage = new int(*p.mage);
        //返回自身
        return *this;
    }
    ~Person(){
        if (mage != NULL){
            delete mage;
            mage = NULL;
        }
    }
};

void test1(){
    Person p1(18);
    Person p2(20);
    Person p3(30);
    p3 = p2 = p1;
    cout << "p1==" << *p1.mage <<endl;
    cout << "p2==" << *p2.mage <<endl;
    cout << "p3==" << *p3.mage <<endl;
}

int main075(){
    test1();

    return 0;
}